<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<meta content="yes" name="apple-mobile-web-app-capable">
		<meta content="yes" name="apple-touch-fullscreen">
		<meta content="telephone=no,email=no" name="format-detection">
		<!--防止css、js资源缓存-->
		<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
		<meta http-equiv="Pragma" content="no-cache" />
		<meta http-equiv="Expires" content="0" />
		<script type="text/javascript" src="asserts/resource/js/flexible_C.js" ></script>
		<title>设置</title>
		 <link rel="stylesheet" href="asserts/resource/mui/css/mui.min.css" />
		<link rel="stylesheet" href="asserts/resource/css/common.css">
    	<link rel="stylesheet" href="asserts/resource/css/css.css">
	</head>
	<body id="settingbody">
		<div class="mui-content setting">
			<ul class="mui-table-view">
			    <li class="mui-table-view-cell">
			        <p class="UserName">
			        	<span class="settingIcon"><i><em>设备编号</em></i></span><span class="FillOut" ><a id="imei"></a></span>
			        </p>
			    </li>
			    <li class="mui-table-view-cell WorkMode Hmsk" data-which = 'WorkMode'>
			        <p class="mui-navigate-right">
			        	<span   class="settingIcon"><i><em>工作模式</em></i></span><span class="FillOut"><a id="settingModle"></a></span>
			        </p>
			    </li>
			    <li class="mui-table-view-cell monitoring Hmsk" data-which = 'monitoring'>
			        <p class="mui-navigate-right">
			        	<span class="settingIcon"><i><em>亲情号码</em></i></span><span class="FillOut"><a id="msg"></a></span>
			        </p>
			    </li>
			    <!--<li class="mui-table-view-cell urgencyhelp Hmsk" data-which = 'urgencyhelp'>-->
			        <!--<p class="mui-navigate-right">-->
			        	<!--<span  class="settingIcon"><i><em>紧急呼救号码</em></i></span><span class="FillOut"><a id="phoneNumber1"></a><a id="phoneNumber2"></a></span>-->
			        <!--</p>-->
			    <!--</li>-->
			    <li class="mui-table-view-cell powerOff" id="confirmBtn">
			        <p class="mui-navigate-right">
			        	<span class="settingIcon"><i><em>远程关机</em></i></span><span class="FillOut"></span>
			        </p>
			    </li>
			    <li class="mui-table-view-cell quipInfo hrefpage" data-which = 'quipInfo'>
			        <p class="mui-navigate-right">
			        	<span class="settingIcon"><i><em>设备信息</em></i></span><span class="FillOut"></span>
			        </p>
			    </li>
			    <li class="mui-table-view-cell revisepassword hrefpage" data-which = 'revisepassword' >
			        <p class="mui-navigate-right">
			        	<span class="settingIcon"><i><em>修改密码</em></i></span><span class="FillOut"></span>
			        </p>
			    </li>
			</ul>

		</div>
		<div class="popupWindow close">
			<div class="Wcontent"></div>
			<div class="buttonWrap">
				
			</div> 
			
		</div>
		<div class="mask close"></div>
	</body>
	<script type="text/javascript" src="asserts/resource/js/jquery.min.js"></script>
	<script type="text/javascript" src="asserts/resource/layer/mobile/layer.js"></script>
	 <script type="text/javascript" src="asserts/resource/mui/js/mui.min.js"></script>
	<script type="text/javascript" src="asserts/resource/js/js.js"></script>

	<script>
	
	var con;
	$(".Wcontent").on("click","p",function(){
		
		//获取点击的内容
		var Mstatus = $(this).find("i.status").attr("data-status");

		var _thisStatus = $(this).find("i.status");
		if(Mstatus == 0){
            _thisStatus.removeClass("TabIconN").addClass("TabIconY").attr("data-status","1");
            $(this).siblings(".flexp").find(".status").removeClass("TabIconY").addClass("TabIconN").attr("data-status","0");
        }
        else{return true;}

		con = $($(this).children("span")[0]).html();
		settingModle=con;
		

	});

	 
	//紧急电话的验证
	function valid($input){	
	
		var phoneNum = $input.val().trim();	
		if(!phoneNum) return false;
		var reg = /^((\+?86)|(\+86))?1[34578]\d{9}$/;
		//固定电话的正则表式
		var tel =  /^([0-9]{3,4}-)?[0-9]{7,8}$/;		
		
		if(reg.test(phoneNum)|| tel.test(phoneNum)){
			return true;
		}
		
		return false;
	}
	
	//告警短信的验证
	function valid2($input){	
	
		var phoneNum = $input.val().trim();	
		//如果没有获取到电话号码，则直接退出
		if(!phoneNum) return false;
		var reg = /^((\+?86)|(\+86))?1[34578]\d{9}$/;
		//固定电话的正则表式
		
		if(reg.test(phoneNum)){
			return true;
		}
		
		return false;
	}
	
	
	
	
	//将设置表中的信息显示在页面上
	function getData(){	
		$.ajax({
			url :'set/selectSetting',
			type : 'post',
			dataType : 'json',
			success : function(back) {
				var  data=back.data;
				if(back.status==1){
					$("#imei").text(data.imei);
					//将时间间隔从数据库中取出来做一个转换
					if(data.postimeInterval=="0"){
						$("#settingModle").text("精准模式(10秒钟一次定位)");
					}else if(data.postimeInterval=="2"){
						$("#settingModle").text("标准模式(5分钟一次定位)");
					}
					
					$("#msg").text(data.msgPhonenum);
					$("#phoneNumber1").text(data.firstCallPhonenum);
					$("#phoneNumber2").text(data.secondCallPhonenum);
					settingModle = data.postimeInterval;
					
					//判断短信的值是否存在
					if(data.msgPhonenum){
						msgPhonenum=data.msgPhonenum;
					}
					//判断告警电话1的值是否存在
					if(data.firstCallPhonenum){
						firstCallPhonenum=data.firstCallPhonenum;	
					}
					//判断告警电话2的值是否存在
					if(data.secondCallPhonenum){
						secondCallPhonenum=data.secondCallPhonenum;
					}
					
				}	
			},
			error : function(back) {

                layerMsg("请求失败！",2)
			}
			
		})
	}
	
	getData();
	
	    //修改工作模式
		function updateModel(){
	    	
	    	//将字符串转成数字的方式存入数据库
	    	var wkModel = $('.p_wrap').find('.TabIconY').parent().siblings().find('i').html();
	    	//页面上显示还是显示字符串
	    	var wordMessage=$('.p_wrap').find('.TabIconY').parent().siblings().html();

		
	    	var option = {
					url :'set/setPostTimeInterval',
					type : 'post',
					dataType : 'json',
					data : {
						postimeInterval :wkModel
					}, 
					success : function(back) {
						
						console.log(back);
						if(!back) return;
						var data = back.data;
						
						if (back.status == 1 || wkModel) {							
							console.log(back.status);
							$("#settingModle").html(wordMessage);
                            layerMsg("设置成功！",2)
						}
					},
					error : function(back) {
                        layerMsg("提交失败！",2)

					}
				};
	    	
			$.ajax(option);
		}
	    
	    //修改短信监控号码
	    function updateMsgPhonenum(){
	    	
	    	if(!valid2($('#sms'))){
                layerMsg("短信号码格式不正确！",2)
	    		return;
	    	}
	    	
	    	$.ajax({
				url :'set/setMsgPhonenum',
				type : 'post',
				dataType : 'json',
				data : {
					 msgPhonenum:$("#sms").val()
				}, 
				success : function(back) {
					var  data=back.data;
					if(back.status == 1){
						$("#msg").html($("#sms").val());
						msgPhonenum = $("#sms").val();
                        layerMsg("设置成功！",2)
						
					}
				},
				error : function(back) {
                    layerMsg("提交失败！",2)
				}
			})
		}

		//修改紧急呼叫电话
		function updatehelpcall() {
			//判断号码1
			if(!valid($('#firstCallPhonenum'))){

                layerMsg("号码格式不正确！",2)
				return ;
			}
			//当号码2不为空的时候进行判断
			if($('#secondCallPhonenum').val()!=null && $('#secondCallPhonenum').val()!=""){	
			 if(!valid($('#secondCallPhonenum'))){

                 layerMsg("号码格式不正确！",2)
				return ;
			} 
			}
			
			$.ajax({
				url : 'set/setCallPhonenum',
				type : 'post',
				dataType : 'json',
				data : {
					//将页面上的值传递到后台
					firstCallPhonenum : $("#firstCallPhonenum").val(),
					secondCallPhonenum : $("#secondCallPhonenum").val()
				},
				success : function(back) {
					var data = back.data;
					if (back.status == 1) {
						//给显示框赋值
						$("#phoneNumber1").html($("#firstCallPhonenum").val())
						$("#phoneNumber2").html($("#secondCallPhonenum").val())		
						//将设置的值显示到输入框
						firstCallPhonenum=$("#firstCallPhonenum").val();
						secondCallPhonenum=$("#secondCallPhonenum").val();

                        layerMsg("设置成功！",2)
					}
				},
				error : function(back) {

                    layerMsg("提交失败！",2)

				}
			})
		}

		document.getElementById("confirmBtn").addEventListener(
				'tap',
				function() {
					var btnArray = [ '否', '是' ];
					mui.confirm('是否确认远程关机？', ' ', btnArray, function(e) {
						if (e.index == 1) {
							document.getElementById("confirmBtn").setAttribute("data-CF", "1");
							$.ajax({
								url:"set/pwoff",
								type:'post',
								dataType:'json',
								success : function(result) {
									if(result.status == 1){

                                        layerMsg("服务请求成功！",2)
									}
								},
								error : function(back) {

                                    layerMsg("服务请求失败！",2)
								}
							})
						} else {
							document.getElementById("confirmBtn").setAttribute("data-CF", "0");
						}
					})
				});
		

		/* 
		var regMobile = '/^0?1[3|4|5|8][0-9]\d{8}$/',
		if (regMobile.test(data)) {
			$('#hint').html('*验证通过');
			$('#hint').css('color', 'green');
			$('#hint').css('display', 'block');
			
			return true;
		} else {
			alert("短信号码输入有误，请检查！");
			return false;
		}

		$("#msg").html($("#sms").val())
		alert(back.msg);

	} */

	</script>
	
</html>
